<template>
  <div>
    员工导入
    <hr>
    <Dass :on-success="onSuccess" :before-upload="beforeUpload" />
  </div>
</template>

<script>
import { sysuserbatch } from '@/api/yuangon'
import dayjs from 'dayjs'
export default {
  // components: {
  //   ccc: () => import('@/components/lib/Uploexecle')
  // },
  methods: {
    // 上传前干什么，文件限制，大小
    // 布尔值来判断通过或阻止
    beforeUpload(res) {
      const a = /\.(xlsx|xls|csv)$/.test(res.name)
      const c = res.size % 1024 % 1024 < 1000

      if (!a) this.$message.error('请注意文件格式')
      if (!c) this.$message.error('请注意文件大小')

      return a && c
      // console.log(res)
    },
    // 上传后干什么
    async onSuccess(res) {
      console.log(res)

      const acc = res.results.map(v => {
        return {
          username: v['姓名'],
          mobile: v['手机号'],
          workNumber: v['工号'],
          correctionTime: v['转正日期'],
          timeOfEntry: this.newdayjs(v['入职日期'])
        }
      })

      await sysuserbatch(acc)
      this.$message.success('导入成功')
      this.$router.push('/Yangon')

      console.log(acc)
    },
    newdayjs(num) {
      const asfs = (num - 25569) * 86400000
      const cc = new Date(asfs)

      return dayjs(cc).format('YYYY--MM--DD')
    }

  }

}
</script>

<style>

</style>
